package service;

import pojo.user;
import util.C3P0Util;
import view.Window;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class loginse {
    static Window begin=new Window();

    public boolean login() throws SQLException, ClassNotFoundException {
       List<user> userList=new ArrayList<>();
       user user ;
       user=begin.insertView();
       boolean bs;
       Connection connection = C3P0Util.getConnection();
       String name=user.getUsername();
       String pw=user.getPassword();
       String sql="select count (*) from j_user where username=? and password=?";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setString(1,name);
        statement.setString(2,pw);
        ResultSet resultSet = statement.executeQuery();
        resultSet.next();
        int i=resultSet.getInt(1);
        if (i>0){
            bs=true;
        }else {
            bs=false;
        }
        return bs;
    }
}
